package com.mqr.wallet.controller;


import com.mqr.wallet.common.Result;
import com.mqr.wallet.service.WalletInfoService;
import com.mqr.wallet.service.WalletTransactionService;
import com.mqr.wallet.vo.WalletVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <B>主类名称：</B>WalletController<BR>
 * <B>概要说明：</B>钱包服务控制组件<BR>
 *
 * @author mqr
 * @since 2023年2月21日 下午12:54:50
 */
@RestController
@RequestMapping("/wallet")
public class WalletController {

    /**
     * 钱包服务service组件
     */
    @Autowired
    private WalletInfoService walletInfoService;

    /**
     * 钱包流水service组件
     */
    @Autowired
    private WalletTransactionService walletTransactionService;


    /**
     * 金额变更接口
     *
     * @return 统一响应Result
     */
    @PostMapping("/amount/change")
    public Result amountChange(WalletVO wallet) {
        walletInfoService.update(wallet);
        return Result.success();
    }

    /**
     * 查询用户的钱包余额
     *
     * @param userId
     * @return
     */
    @GetMapping("/info/{userId}")
    public Result walletInfo(@PathVariable("userId") Integer userId) {
        return Result.success(walletInfoService.findByUserId(userId));
    }

    /**
     * 查询用户钱包流水信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/transaction/{userId}")
    public Result walletTransactionInfo(@PathVariable("userId") Integer userId) {
        return Result.success(walletTransactionService.findByUserId(userId));
    }


}
